<template>
  <div class="home">
    <input type="text" placeholder="请输入用户名"  v-model="username">
    <button @click="login">登录</button>
  </div>
</template>

<script>


export default {
  name: 'Home',
  data(){
    return{
      username:""
    }
  },
  mounted () {
    let username = localStorage.getItem('username')
    if(username){
      this.$router.push('/index')
      return
    }
  },
  methods: {
    login(){
      let username = this.username.trim()
      if(username.length<6){
        alert('用户名不能小于6位')
        return
      }
      localStorage.setItem('username',username)
      this.$router.push('/index')
    }
  }
}
</script>
